import {router} from "@/config/router";
import {whiteList} from "@/permissionWhiteList"
import {getUserInfo} from "@/utils/storageUtil";

router.beforeEach((to,from,next) =>{
    if (to.path == '/login'){
        next();
    }else if(whiteList.indexOf(to.name) > -1) {
        // 当前路由在白名单中,放行
        next();
    }else {
        //登录后会把登录信息存储在 sessionStorage 中
        let userInfo = JSON.parse(getUserInfo());
        if (userInfo){
            let menuIds = userInfo.menus;
             if (menuIds.indexOf(to.name) > -1){
                 next();
             }else {
                next({name:'error',})
            }
        }else {
            next({name:'login',params:{msg:'登陆信息已过期,请重新登陆'}});
        }
    }

})
